home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Monster Media 1994 #2
/
Monster Media No. 2 (Monster Media)(1994).ISO
/
prog_gen
/
gcoope10.zip
/
GENERICS.TXT
< prev
next >
Wrap
Text File
|
1994-07-22
|
5KB
|
163 lines
The generic functions in GCOOPE Version 1.0 initial release.
by Brian Lee Price
Released as Public Domain July, 1994.
I. The flavors of New, the following constructors are defined:
A. Class constructor
form of call;
1. normal
newclass=g(New)(Class, classVarSize, instanceVarSize,
ancestor list terminated by END);
2. strong typing
newclass=NEW(Class)(Class, classVarSize, instanceVarSize,
ancestor list terminated by END);
this call creates an instance of Class, ie a new class.
should only be called from within a CLASS_INSTALL function.
B. Other constructors
form of call;
1. normal
newobject=g(New)(className, initialParameters);
2. strong typing
newobject=NEW(className)(className, initialParameters);
The form of the parameter list is given in each class description.
II. Other generic functions:
A. Impossible to prototype generics;
changeVal and valueOf are pretty much impossible to deal with
under strong typing. For valueOf, you can use the return
value type casts given in gcoope10.h.
The trouble with changeVal is although it always returns an
object type and always takes an object type as the first
parameter, the second parameter is a different type for every
object class it is defined for. Still, I'd rather pass by
value and take my chances with weak typing than go through
the pains of passing by pointer.
valueOf has the opposite problem, it always takes only one
parameter of type object, but its return value changes for
each object class it is defined for. In gcoope10.h there
are some return value method typecasts defined that can
help you avoid many problems, but you still must know what
type to expect.
For both of the above, the primary usage should be by other
class definitions rather than applications programs, this
should at least localize any problems.
Accessing:
The above generics should be called in the following
manner:
1. normal
returnValue= ((returnTypeCast)g)(genName)(parms);
2. strong typing
returnValue= ((returnTypeCast)g)(GEN(genName))(parms);
B. Standard format generics;
The following generic functions have a standardized interface,
they always return the same type and always take the same
number and type of parameters regardless of the class definition
for which they are defined.
I'm going to show them here as standard function prototypes, but
bear in mind that you must call them as follows:
1. normal
returnValue= ((returnTypeCast) g)(genName)(parameters);
2. strong typing
returnValue= G(genName)(parameters);
Here are the generics given as standard prototypes:
object reSize(object, word)
object putElem(object, word, void *)
void * getElem(object, word)
word sizeOf(object)
word lengthOf(object)
word numElems(object)
object classOf(object)
object ivSize(object)
object respondsTo(object, generic)
object deepCopy(object)
object shallowCopy(object, object)
object asString(object)
object asHexStr(object)
object asShortInt(object)
object asLongInt(object)
object asUnsigned(object)
object asChar(object)
int addUnit(object, void *)
object rmvUnit(object, int)
void * getUnit(object, int)
object compact(object, boolean)
long getPos(object)
object strmErr(object)
object setPos(object, long, int)
object putByte(object, byte)
object getByte(object)
object clrErr(object)
object SetBuf(object, char *, int, word)
object Flush(object)
object Stat(object)
int Putc(object, char)
int Getc(object)
int UnGet(object, char)
int Puts(object, const char *)
void * Gets(object, char *, int)
int Write(object, const char *, word, word)
int Read(object, char *, word, word)
void * addressOf(object)
Most of these generics should be self explanatory, however
consult the class definitions for details. Also note that when
possible, I have attempted to stay with the standard ANSI C
function library prototypes.
A final reminder, don't try to use the prototypes above
directly, use either the return type casting as needed or
the strong typing option with the g or G dispatch call.
The above goes to show that if you beat C firmly about the
neck and shoulders with an appropriately sized sledgehammer, you
can combine a reasonable degree of static type checking with
run-time OOP flexibility.